#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>

using namespace std;

typedef long long ll;
typedef double db;

#define in read()
#define pii pair<int,int>
#define fi first
#define se second
#define FILE(x) freopen(x".in","r",stdin);\
	freopen(x".out","w",stdout);
#define pb push_back

int read(){
	int x = 0,sgn = 1;char ch = getchar();
	for(;!isdigit(ch);ch = getchar()) if(ch == '-') sgn = -1;
	for(;isdigit(ch);ch = getchar()) x = (x<<1)+(x<<3)+(ch^48);
	return x*sgn;
}

const int N = 2e6+10;
const int M = 8e5+10;

ll tr[N],ans[M];
int p[M],q[M],x[M],y[M],t[M],val[M],n,tp[M],tim,tot,id[M],cnt;

void add(int x,int y){x++;for(;x <= n+1;x+=x&-x) tr[x]+=y;}
ll query(int x,ll y = 0){x++;for(;x;x-=x&-x) y += tr[x];return y;}

bool cmp(int a,int b){return t[a] ^ t[b] ? t[a] < t[b] : (x[a] ^ x[b] ? x[a] < x[b] : y[a] < y[b]);}

void CDQ(int *p,int len){
	if(len == 1) return; int m = len >> 1,l,r,k;
	CDQ(p,m); CDQ(p+m,len-m);
	memcpy(q,p,len<<2);
	for(l = k = 0,r = m;l < m && r < len;k++){
		if(x[q[l]] <= x[q[r]]){
			if(tp[q[l]] == 1) add(y[q[l]],val[q[l]]); p[k] = q[l++];
		}else{
			if(tp[q[r]] == 2) ans[id[q[r]]] += query(y[q[r]]) * val[q[r]]; p[k] = q[r++];
		}
	}for(;r < len;r++) if(tp[q[r]] == 2) ans[id[q[r]]] += query(y[q[r]]) * val[q[r]];
	memcpy(p+k,q+l,(m-l)<<2);
	for(--l;~l;--l) if(tp[q[l]] == 1) add(y[q[l]],-val[q[l]]);
}

int main (){
#ifndef ONLINE_JUDGE
	freopen("1.in","r",stdin);
#endif
	int op = in; n = in;
	while((op = in) != 3){
		int x1 = in,y1 = in,a = in,b; if(op == 2) b = in,cnt++; tim++;
		if(op == 1) x[++tot] = x1,y[tot] = y1,val[tot] = a,tp[tot] = 1,t[tot] = tim;
		else {
			x[++tot] = a,y[tot] = b,val[tot] = 1; tp[tot] = 2; t[tot] = tim; id[tot] = cnt;
			x[++tot] = x1-1,y[tot] = y1-1,val[tot] = 1; tp[tot] = 2; t[tot] = tim; id[tot] = cnt;
			x[++tot] = a,y[tot] = y1-1,val[tot] = -1; tp[tot] = 2; t[tot] = tim; id[tot] = cnt;
			x[++tot] = x1-1,y[tot] = b,val[tot] = -1; tp[tot] = 2; t[tot] = tim; id[tot] = cnt;
		}
	}for(int i = 0;i < tot;i++) p[i] = i;
	sort(p,p+tot,cmp);
	CDQ(p,tot); for(int i = 1;i <= cnt;i++) printf("%lld\n",ans[i]);
	return 0;
}

